﻿<?php
	include '../inc/conn.php';
	session_start();
	extract($_POST);
	extract($_GET);
	unset($_POST,$_GET);
	
	if(!isset($_SESSION['logname'])){
		die("<div>User Session is missing</div>");
	}
	
	if (isset($act) && isset($id))
	{
		if (empty($iReason) ||empty($vContent) || empty($iOwner) 
			|| empty($iStatus)){
			echo "<script>alert('Some content must be filled in data!!');window.history.go(-1);</script>";
			die("Some content must be filled in data!");
		}
	
		if(empty($iRC)) $iRC='NA';
		if(empty($iPurpose) ) $iPurpose='NA';
		if(empty($iScheme)) $iScheme='NA';
		if(empty($iFailrate)) $iFailrate='NA';
	
		if ($act == 'mod')
		{	
			date_default_timezone_set('Asia/Shanghai');
			$db = new mysql();
			$table = "validate_issues";
			$condition = "id=".$id;
			$mod_content="val_reason=\"".htmlentities($iReason,ENT_QUOTES)."\", val_purpose=\"".htmlentities($iPurpose,ENT_QUOTES)."\", 
			val_scheme=\"".htmlentities($iScheme,ENT_QUOTES)."\", val_failrate=\"".htmlentities($iFailrate,ENT_QUOTES).
			"\", val_content=\"".htmlentities($vContent,ENT_QUOTES)."\", val_owner=\"".htmlentities($iOwner,ENT_QUOTES)."\", 
			val_status=\"".htmlentities($iStatus,ENT_QUOTES)."\", val_rootcause=\"".htmlentities($iRC,ENT_QUOTES)."\", val_duty=\"".htmlentities($iDuty,ENT_QUOTES)."\"";	
			
			$db->update($table, $mod_content, $condition);
			$db->close();
			echo "<script>alert('数据修改完成!');window.opener.location.reload();window.close();</script>";
		}
	}
	
	if (!isset($id))
	{
		echo "<script>alert('ID is empty!');</script>";
		die("ID is empty!");
	}
	$db = new mysql();
	$sql = "select * from validate_issues where id=".$id;
	$db->query($sql);
	$num = $db->db_num_rows();
	if ($num == 0)
		die("No data was found!");
	$row = $db->fetch_assoc();
?>
<!DOCTYPE html>
<html>
<head>
<title>修改 "<? echo htmlspecialchars_decode($row['val_reason']); ?>" 详细信息</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">-->
<link rel="stylesheet" href="/css/bootstrap.min.css">
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery-migrate.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor.min.js"></script>
<script type="text/javascript" src="/xhEditor/xheditor_lang/zh-cn.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<style>
<!--
.xheDialog label {
	display: inline;
}
.form-horizontal .control-label {
	width: 80px;
}
.form-horizontal .controls {
	margin-left: 20px;
}
-->
</style>
</head>
<body class="background">
<?
	include "admin_top.php";
?>
<div class="container white-background pagecontent">
<div class="panel panel-primary">
    <div class="panel-heading">
        <h3 class="panel-title">修改 "<? echo htmlspecialchars_decode($row['val_reason']); ?>" 详细信息</h3>
    </div>
    <div class="panel-body">
	<form action="mod_issue.php?id=<? echo $id; ?>&act=mod" method="post" enctype="application/x-www-form-urlencoded">
	<div class="input-group">
		<span class="input-group-addon">问题描述:</span>
		<input name="iReason" type="text" value="<? echo htmlspecialchars_decode($row['val_reason']); ?>" class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">问题结论:</span>
		<input name="iRC" type="text" value="<? echo htmlspecialchars_decode($row['val_rootcause']); ?>" class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">短期对策:</span>
		<input name="iPurpose" type="text" value="<? echo htmlspecialchars_decode($row['val_purpose']); ?>" class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">长期对策:</span>
		<input name="iScheme" type="text" value="<? echo htmlspecialchars_decode($row['val_scheme']); ?>" class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">不良状况:</span>
		<input name="iFailrate" type="text" value="<? echo htmlspecialchars_decode($row['val_failrate']); ?>" class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">分析人员:</span>
		<input name="iOwner" type="text" value="<? echo htmlspecialchars_decode($row['val_owner']); ?>" class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">责任单位:</span>
		<input name="iDuty" type="text" value="<? echo htmlspecialchars_decode($row['val_duty']); ?>" class="form-control">
	</div>
	<div class="input-group">
		<span class="input-group-addon">问题状态:</span>
		<select name="iStatus" id="iStatus"  class="form-control">
		<? 
			if ($row['val_status'] == "Open") 
				echo '<option value="Open" selected="selected">Open</option>';
			else
				echo '<option value="Open">Open</option>';
				
			if ($row['val_status'] == "Tracking") 
				echo '<option value="Tracking" selected="selected">Tracking</option>';
			else
				echo '<option value="Tracking">Tracking</option>';
			
			if ($row['val_status'] == "Close") 
				echo '<option value="Close" selected="selected">Close</option>';
			else
				echo '<option value="Close">Close</option>';	
		?>
		</select>
	</div>
<div>
分析步骤:<br />
<textarea name="vContent" class="xheditor {tools:'full',skin:'default', upImgUrl:'upload.php?immediate=1'}" style="width:100%;height:280px; display:none;">
<?
	echo htmlspecialchars_decode($row['val_content']);
?>
</textarea>
</div>
<div><input class="btn btn-success btn-primary" name="submit" value="修改" type="submit"><input class="btn btn-danger" name="reset" value="重填" type="reset"></div>
</form>
</div>
</div>
</div>
<?
include '../bottom.php';
?>
</body>
</html>
<?
	$db->close();
?>
